<!DOCTYPE html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.lingyun.ucm.common.pojo.bean.BusinessSystem" %>
<%@ page import="com.lingyun.ucm.common.pojo.bean.BusinessModule" %>
<%@ page import="com.lingyun.ucm.common.pojo.bean.ConfigBean" %>
<html lang="zh-CN">
<head>
    <%@include file="/resource/common/head.jsp" %>
</head>
<script>
    function saveConfig(systemName, moduleName) {
        $("#saveForm input[name='systemName']").val(systemName);
        $("#saveForm input[name='moduleName']").val(moduleName);
        $("#saveForm input[name='operation']").val("save");
        $("#saveLabel").html(systemName + "." + moduleName + ".");
    }

    function updateConfig(systemName, moduleName, configKey, configValue) {
        $("#updateForm div input[name='configKey']").val(configKey);
        $("#updateForm div input[name='configValue']").val(configValue);
        $("#updateForm input[name='systemName']").val(systemName);
        $("#updateForm input[name='moduleName']").val(moduleName);
        $("#updateForm input[name='oldConfigKey']").val(configKey);
        $("#updateForm input[name='operation']").val("update");
        $("#updateLabel").html(systemName + "." + moduleName + ".");
    }

    function deleteConfig(systemName, moduleName, configKey) {
        $("#deleteForm input[name='systemName']").val(systemName);
        $("#deleteForm input[name='moduleName']").val(moduleName);
        $("#deleteForm input[name='configKey']").val(configKey);
    };

    function saveModule(systemName, moduleName) {
        $("#saveModuleForm div input[name='systemName']").val(systemName);
        $("#saveModuleForm input[name='moduleName']").val(moduleName);
    }

    function deleteModule(systemName, moduleName) {
        $("#deleteModuleForm input[name='systemName']").val(systemName);
        $("#deleteModuleForm input[name='moduleName']").val(moduleName);

    };
</script>
<body>
<div id="wrapper">
    <%@include file="/resource/common/navigator.jsp" %>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">${businessSystemsList.get(0).systemName} 业务系统</h1>
            </div>
        </div>
        <div class="row">
            <c:forEach items="${businessSystemsList}" var="businessSystem">
                <c:forEach items="${businessSystem.modules}" var="businessModule">
                    <div class="col-lg-6">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <span class="pull-left"><h4>${businessModule.moduleName} 模块</h4></span>
                                <span class="pull-right">
                                    <div class="">
                                        <!--删除功能模块配置  -->
                                        <button title="删除功能模块配置" class="btn btn-danger" data-toggle="modal" data-target="#deleteModuleModal"
                                                onclick="deleteModule('${businessSystem.systemName}','${businessModule.moduleName}')">
                                            <i class="fa fa-trash-o"></i>
                                        </button>
                                    </div>
                                </span>
                                <div class="clearfix"></div>
                            </div>
                            <div class="panel-body">
                                <div class="table-responsive">
                                    <table class="table table-hover">
                                        <thead>
                                        <tr>
                                            <th>配置项</th>
                                            <th>配置值</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:forEach items="${businessModule.configBeans}" var="config">
                                            <tr>
                                                <td>${businessSystem.systemName}.${businessModule.moduleName}.${config.configName}</td>
                                                <td>${config.configStoreValue.value}</td>
                                                <td>
                                                    <span class="pull-left">
                                                        <!--编辑配置  -->
                                                        <button title="编辑配置项" class="btn btn-info"
                                                                <c:if test="${!config.configStoreValue.canEdit}">disabled="true"</c:if>
                                                                data-toggle="modal" data-target="#updateModal"
                                                                onclick="updateConfig('${businessSystem.systemName}','${businessModule.moduleName}','${config.configName}','${config.configStoreValue.value}')">
                                                            <i class="fa fa-edit"></i>
                                                        </button>
                                                        <!--删除配置  -->
                                                        <button title="删除配置项" class="btn btn-danger"
                                                                <c:if test="${!config.configStoreValue.canDel}">disabled="true"</c:if>
                                                                data-toggle="modal" data-target="#deleteModal"
                                                                onclick="deleteConfig('${businessSystem.systemName}','${businessModule.moduleName}','${config.configName}')">
                                                            <i class="fa fa-trash-o"></i>
                                                        </button>
                                                    </span>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                        <tr>
                                            <td></td>
                                            <td></td>
                                            <td>
                                                <span class="pull-left">
                                                    <!-- 新增功能模块配置项配置-->
                                                    <button title="新增功能模块配置项配置" class="btn btn-info" data-toggle="modal" data-target="#saveModal"
                                                            onclick="saveConfig('${businessSystem.systemName}','${businessModule.moduleName}')">
                                                        <i class="fa fa-plus"></i>
                                                    </button>
                                                </span>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:forEach>
                <!-- 模块新增 begin -->
                <div class="col-lg-6">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="text-center">
                                <button title="新增功能模块配置" type="button" class="btn btn-info btn-circle btn-xl" data-toggle="modal" data-target="#saveModuleModal"
                                        onclick="saveModule('${businessSystem.systemName}','${businessModule.moduleName}')">
                                    <i class="fa fa-plus"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 模块新增 end -->
            </c:forEach>
        </div>
        <%--新增弹框--%>
        <div class="modal fade" id="saveModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="saveModalLabel">新增配置项</h4>
                    </div>
                    <form id="saveForm" role="form" action="${basePath}/configs4detail" method="post">
                        <div class="modal-body">
                            <div class="form-group">
                                <label>配置项</label><br>
                                <label id="saveLabel"></label>
                                <input class="" name="configKey" placeholder="configKey">
                            </div>
                            <div class="form-group">
                                <label>配置值</label>
                                <input class="form-control" name="configValue" placeholder="configValue">
                            </div>
                            <div class="form-group">
                                <div style="display:inline;margin-right: 15%;">
                                    <label>是否可编辑 : </label>
                                    <select name="canEdit" style="width: 20%;">
                                        <option value="1" aria-checked="true">是</option>
                                        <option value="0">否</option>
                                    </select>
                                </div>
                                <div style="display:inline;">
                                    <label>是否可删除 : </label>
                                    <select name="canDel" style="width: 20%;">
                                        <option value="1" aria-checked="true">是</option>
                                        <option value="0">否</option>
                                    </select>
                                </div>
                            </div>
                            <input type="hidden" name="systemName">
                            <input type="hidden" name="moduleName">
                            <input type="hidden" name="operation">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>
        <%--编辑弹框--%>
        <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="updateModalLabel">编辑配置项</h4>
                    </div>
                    <form id="updateForm" role="form" action="${basePath}/configs4detail" method="post">
                        <div class="modal-body">
                            <div class="form-group">
                                <label>配置项</label><br>
                                <label id="updateLabel"></label>
                                <input class="" name="configKey" placeholder="configKey">
                            </div>
                            <div class="form-group">
                                <label>配置值</label>
                                <input class="form-control" name="configValue" placeholder="configValue">
                            </div>
                            <input type="hidden" name="systemName">
                            <input type="hidden" name="moduleName">
                            <input type="hidden" name="oldConfigKey">
                            <input type="hidden" name="operation">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>
        <%--删除配置弹框--%>
        <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="deleteModalLabel">删除配置项</h4>
                    </div>
                    <form id="deleteForm" role="form" action="${basePath}/configs4detail" method="post">
                        <div class="modal-body">
                            确定删除该配置吗?
                            <input type="hidden" name="systemName">
                            <input type="hidden" name="moduleName">
                            <input type="hidden" name="configKey">
                            <input type="hidden" name="operation" value="delete">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">确定</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>
        <%--新增功能模块--%>
        <div class="modal fade" id="saveModuleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">新增功能模块</h4>
                    </div>
                    <form id="saveModuleForm" role="form" action="${basePath}/configs4detail" method="post">
                        <div class="modal-body">
                            <div class="form-group">
                                <label>功能模块名称</label>
                                <input class="form-control" name="moduleName" placeholder="moduleName">
                            </div>
                            <input type="hidden" name="systemName">
                            <input type="hidden" name="operation" value="saveModule">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>
        <%--删除功能模块弹框--%>
        <div class="modal fade" id="deleteModuleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="">删除功能模块</h4>
                    </div>
                    <form id="deleteModuleForm" role="form" action="${basePath}/configs4detail" method="post">
                        <div class="modal-body">
                            确定删除该功能模块吗?
                            <input type="hidden" name="systemName">
                            <input type="hidden" name="moduleName">
                            <input type="hidden" name="operation" value="deleteModule">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">确定</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>
    </div>
    <!-- 页面依赖js文件 -->
    <%@include file="/resource/common/scripts.jsp" %>
</body>
<script>

</script>
</html>
